﻿using System;
using System.Collections.Generic;
using System.Drawing;
using viBlog.Classes;
using viBlog.Controllers;
using visinia.SmartEngine;

public partial class Admin_Pages_viBlog_Comments_Comments : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ShowAllComments();
            List<Comment> AllCommentsList = CommentController.GetCommentsAdmin();
            AllComments.Text = "All(" + AllCommentsList.Count + ")";
            List<Comment> PendingCommentsList = CommentController.GetPendingCommentsAdmin();
            PendingComments.Text = "Pending(" + PendingCommentsList.Count + ")";
            List<Comment> ApprovedCommentsList = CommentController.GetApprovedCommentsAdmin();
            ApprovedComments.Text = "Approved(" + ApprovedCommentsList.Count + ")";
        }
        if (string.Compare(Request.QueryString["View"], "Pending", true) == 0)
        {
            ShowPendingComments();
        }
        if (string.Compare(Request.QueryString["View"], "Approved", true) == 0)
        {
            ShowApprovedComments();
        }
    }

    protected void AllComments_Click(object sender, EventArgs e)
    {
        ShowAllComments();
    }

    private void ShowAllComments()
    {        
        COMMENTS.DataSource = CommentController.GetCommentsAdmin();
        COMMENTS.DataBind();
        if (AllComments.ForeColor != Color.Black)
        {
            PendingComments.ForeColor = AllComments.ForeColor;
            PendingComments.Style["font-weight"] = AllComments.Style["font-weight"];
            ApprovedComments.ForeColor = AllComments.ForeColor;
            ApprovedComments.Style["font-weight"] = AllComments.Style["font-weight"];
            AllComments.ForeColor = Color.Black;
            AllComments.Style["font-weight"] = "bold";
        }
    }
    protected void PendingComments_Click(object sender, EventArgs e)
    {
        ShowPendingComments();
    }

    private void ShowPendingComments()
    {
        COMMENTS.DataSource = CommentController.GetPendingCommentsAdmin();
        COMMENTS.DataBind();
        if (PendingComments.ForeColor != Color.Black)
        {
            AllComments.ForeColor = PendingComments.ForeColor;
            AllComments.Style["font-weight"] = PendingComments.Style["font-weight"];
            ApprovedComments.ForeColor = PendingComments.ForeColor;
            ApprovedComments.Style["font-weight"] = PendingComments.Style["font-weight"];
            PendingComments.ForeColor = Color.Black;
            PendingComments.Style["font-weight"] = "bold";
        }
    }
    protected void ApprovedComments_Click(object sender, EventArgs e)
    {
        ShowApprovedComments();
    }

    private void ShowApprovedComments()
    {
        COMMENTS.DataSource = CommentController.GetApprovedCommentsAdmin();
        COMMENTS.DataBind();
        if (ApprovedComments.ForeColor != Color.Black)
        {
            AllComments.ForeColor = ApprovedComments.ForeColor;
            AllComments.Style["font-weight"] = ApprovedComments.Style["font-weight"];
            PendingComments.ForeColor = ApprovedComments.ForeColor;
            PendingComments.Style["font-weight"] = ApprovedComments.Style["font-weight"];
            ApprovedComments.ForeColor = Color.Black;
            ApprovedComments.Style["font-weight"] = "bold";
        }
    }

    public string GetEditLink(int Commentid)
    {
        return SystemMenu.CallPage("viBlog", "EditComment", "CommentId", Commentid.ToString());
    }    

    protected void COMMENTS_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DeleteComment")
        {
            int CommentId = Convert.ToInt32(e.CommandArgument);
            CommentController.DeleteComment(CommentId);            
            Response.Redirect(Request.RawUrl);
        }
    }
}
